package com.com.knowledgepaymentmanagementsystem.controller.course;

import com.com.knowledgepaymentmanagementsystem.pojo.course.Live;
import com.com.knowledgepaymentmanagementsystem.service.course.LiveService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/22 上午11:31
 */

@RestController
@CrossOrigin
@Api(tags = "课程管理")
@RequestMapping("/live")
public class LiveController {

    @Autowired
    private LiveService liveService;


    @ApiOperation(value = "查询直播课程",httpMethod = "POST",notes = "查询直播课程")
    @PostMapping("/find")
    public ResultUtil<List<Live>> getLives(@RequestBody Live live){
        List<Live> lives = liveService.getLive(live);
        try {
            return new  ResultUtil<>(200,"查询成功",lives);
        } catch (Exception e) {
            e.printStackTrace();
            return new  ResultUtil<>(200,"查询失败");

        }
    }

    @ApiOperation(value = "新增直播课程",httpMethod = "POST",notes = "新增直播课程")
    @PostMapping("insert")
    public ResultUtil insertLives(@RequestBody Live live){
        try {
            return new ResultUtil<>(200,"新增成功",liveService.insertLives(live));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "修改直播课程",httpMethod = "PUT",notes = "修改直播课程")
    @PutMapping("/update")
    public ResultUtil updateLives(@RequestBody Live live){

        liveService.updateLives(live);
        try {
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");

        }
    }

    @ApiOperation(value = "删除直播课程",httpMethod = "DELETE",notes = "删除直播课程")
    @DeleteMapping("/delete")
    public ResultUtil deleteLives(Integer id){
        liveService.deleteLives(id);
        try {
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");

        }
    }

}
